import { hasReadInfo, deleteMessage, fetchList, fetchDashBoardInfo, fetchBugList, fetchMessageList, removeAllMessage, readAllMessage } from "@/api/dealmessage/index"

const state = {
    list: [],
    total: 0,
    totalInfo: {},
    bugList: [],
    bugTotal: 0,
    messageList: [],
    messageTotal: 0

}

const mutations = {
    SET_LIST: (state, args) => {
        state.list = args.records
        state.total = args.total
    },
    SET_TOTALINFO: (state, args) => {
        state.totalInfo = args
    },
    SET_BUG: (state, args) => {
        state.bugList = args.records
        state.bugTotal = args.total
    },
    SET_MESSAGE_LIST: (state, args) => {

        state.messageList = args.records
        state.messageTotal = args.total
    }
}

const actions = {
    //查询消息中心分页
    requestMessageList({ commit, state }, args) {
        return fetchMessageList(args).then(response => {
            commit('SET_MESSAGE_LIST', response.data)
        })
    },
    //请求待办事项
    requestList({ commit }, args) {
        return fetchList(args).then(response => {
            commit('SET_LIST', response.data)

        })
    },
    //请求工作台左一模块
    requestTotalInfo({ commit }, args) {
        return fetchList(args).then(response => {
            commit('SET_LIST', response.data)

        })
    },
    //请求工作台图表数据
    requestChartInfo({ commit }, args) {
        return fetchList(args).then(response => {
            commit('SET_LIST', response.data)

        })
    },
    //请求七天故障明细
    resuestBugList({ commit }, args) {
        return fetchBugList(args).then(response => {
            commit('SET_BUG', response.data)

        })
    },
    questDashBoardInfo({ commit }, args) {
        return fetchDashBoardInfo().then(res => {
            commit("SET_TOTALINFO", res.data)
            return res.data
        })
    },
    //全部已读
    readAllMessage({ commit }, args) {
        return readAllMessage()
    },
    //清空消息
    removeAllMessage({ commit }, args) {
        return removeAllMessage()
    },
    //删除
    deleteDeviceInfo({ commit }, args) {
        return deleteMessage(args)
    },
    //标记已读
    hasRead({ commit }, args) {
        return hasReadInfo(args)
    }

}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}